package com.fang.bank2;

public class Bank {
    private int account = 100;
    private Object object = new Object();
    public  int getAccount(int order) {
        synchronized (object) {
            if (account >= order) {
                System.out.println(Thread.currentThread().getName() + "正在取钱。。。。。");
                System.out.println("系统正在处理中。。。。。");
                try {
                    long m = (long) (Math.random() * 2000 + 600);
                    Thread.sleep(m);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                account -= order;
                System.out.println("尊敬的" + Thread.currentThread().getName() + "用户，您要提取的金额为：" + order + ",您的账户的余额:" + account);
                return order;
            } else {
                System.out.println("系统出现错误，您的账户余额不足");
                return 0;
            }
        }
    }
}
